-
-
Notifications
You must be signed in to change notification settings - Fork 122
Add "print-config" subcommand #698
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
|
Just wanted to let you know I will need some more time in order to do a proper review here. I'm very happy the PR is here in any case. |
|
No worries, frohe Weihnachten! btw I’m not too happy with the flag parsing, I think my implementation could be improved |
18db772 to
13e54e1
Compare
m90
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good, I left some comments inline, let me know what you think.
There's one bigger question left for me in this: should there also be an option that "resolves" configuration values as deeply as possible, i.e. reads Docker secrets, expands shell variables, and renders config options that are templates? Or should this be the default even?
I was under the false impression that I'll have a go to see if I can resolve without adding too much complexity. |
I would think it'd be a good thing to at least evaluate how much effort modeling things like this would be. |
I added some simple logic to resolve env vars when This is an AI analysis of what it would take to resolve all env variables:
|
cmd/backup/print_config.go
Outdated
| func runPrintConfig() error { | ||
| configurations, err := sourceConfiguration(configStrategyConfd) | ||
| if err != nil { | ||
| fmt.Printf("error sourcing configuration: %v\n", err) // print error to stdout for debugging |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure this is needed as I would expect the returned error to be printed as well on exit? Or is that not happening and the mechanism is broken?
Also applies below.
| ) | ||
|
|
||
| func runPrintConfig() error { | ||
| configurations, err := sourceConfiguration(configStrategyConfd) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What happens when no configuration directory is present and configuration is provided via env vars only? Does it fall back to env? Sorry, it's been a while since I have written this 😅
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not sure I understand this comment. Is test/print-config/docker-compose.yml using only env variables?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems to fall back if no directory is mounted, so never mind. See:
docker-volume-backup/cmd/backup/config_provider.go
Lines 34 to 42 in 4531c60
| case configStrategyConfd: | |
| cs, err := loadConfigsFromEnvFiles("/etc/dockervolumebackup/conf.d") | |
| if err != nil { | |
| if os.IsNotExist(err) { | |
| return sourceConfiguration(configStrategyEnv) | |
| } | |
| return nil, errwrap.Wrap(err, "error loading config files") | |
| } | |
| return cs, nil |
|
I had another look at the original issue: #628 which made me think we should check how the output handles trailing newlines here. Just writing this down so we don't forget. |
6b95191 to
4875396
Compare
Do you have any ideas how to handle this? |
How does the current mechanism display a value with a trailing new line? I don't necessarily have an opinion on how exactly this should look like, but it should be obvious that it's really the configuration that contains the newline, not the |
| formatter := regexp.MustCompile(`\s([A-Z])`) | ||
| for _, config := range configurations { | ||
| if err := func() error { | ||
| unset, warnings, err := config.resolve() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there any reason you don't use defer unset() here? Btw, it cannot be nil, so there's no need to check if it is.
Addresses #628
Approach
I looked into how shouterrr pretty-prints its verify function and tried to find the best poor-mans approach to it.
I wanted to add a little bit of formatting, because without any formatting, the output is pretty hard to read. So I landed on a basic regex based formatter.
I played around with coloring the output as well, but I ended up with a lot of code for a nice-to-have, so I removed it again.